import { createStore } from "vuex";
import getters from "./getters";
// import user from "./modules/user";
// import app from "./modules/app";

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
// const modulesFiles = import.meta.globEager('./modules/*.js')

// const modules = modulesFiles.keys().reduce((modules, modulePath) => {
//   // set './app.js' => 'app'
//   const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
//   const value = modulesFiles(modulePath)
//   modules[moduleName] = value.default
//   return modules
// }, {})

const modulesFiles = import.meta.globEager('./modules/*.js')
// console.log(modulesFiles)
const modules = Object.keys(modulesFiles).reduce((modules, modulesPath) => {
  const modulesName = modulesPath.replace(/(.*\/)*([^.]+).*/gi, '$2')
  // console.log(modulesName)
  modules[modulesName] = modulesFiles[modulesPath].default
  return modules
}, {})

const store = createStore({
  getters,
  modules
});
export default store
